var KB = function(str){
	this.nod = new Array();
	return this.init(str);
}
KB.prototype={
	version:'1.0',
	init: function(str){
		str = str||document;
		if(str.nodeType ) {
			return this;
		} else if ( typeof str == "string" ) {
				this.proStr = str;
				this.nodParent = document;
				var tm = str.split(":");
				if(tm.length>1){
					for(var i=0; i<tm.length; i++){
						this.getNodes(tm[i]);
					}
					return this;
				}else{
					return this.getNodes(str);
				}
				
		}
	},
	getNodes:function(str){
		this.proStr = str;
		if(str.indexOf('=')!=-1){
			this.getId();	
		}else if(str.indexOf('@')!=-1){
			this.getCN();	
		}else if(str.indexOf('&')!=-1){
			this.getN();
		}else{
			this.getEN();	
		}
		this.nodParent = this.nod[1];
		typeof this.nodParent == "undefined"?this.nodParent = document:this.nodParent;
		return this;
	},
	getChild:function(c){
		var f = new Array();
		if(typeof this.nod[0]=='undefined')return f;
		var s = this.nod[0].getElementsByTagName(c);
		for(var i=0; i<s.length; i++){
			f.push(s[i]);
		}
		return f;
	},
	getParent:function(){
		var arr = new Array();
		for(var i=1; i<this.nod.length; i++){
			arr.push(this.nod[i].parentNode);	
		}
		return arr;
	},
	getId : function(){
		var a = this.proStr.split('=');
		this.nod[0] = this.nod[1] = this.nodParent.getElementById(a[1]);
		return this;
	},
	getCN : function(){
		var a = this.proStr.split('@');
		var s = this.nodParent.getElementsByTagName(a[0]);
		var ii = 1;
		for(var i=0; i<s.length; i++){
			if((' '+s[i].className+' ').indexOf(' '+a[1]+' ')!=-1){
				this.nod[ii] = s[i];
				ii++;
			}
		}
		this.nod[0] = this.nod[1];
		return this;
	},
	getN : function(){
		var a = this.proStr.split('&');
		var s = this.nodParent.getElementsByTagName(a[0]);
		var ii = 1;
		for(var i=0; i<s.length; i++){
			if(s.item(i).getAttribute(a[1])){
				this.nod[ii] = s[i];
				ii++;
			}
		}
		this.nod[0] = this.nod[1];
		return this;
	},
	getEN : function(){
		var s = this.nodParent.getElementsByTagName(this.proStr);
		for(var i=0; i<s.length; i++){
			this.nod[i+1] = s[i];	
		}
		this.nod[0] = this.nod[1];
		return this;	
	},
	getNod: function(val){
		var t = this.nod.length-1;
		if(val<0)val=0;
		if(val>=t){this.nod[0]=this.nod[t];return this;}
		this.nod[0] = this.nod[val];
		this.nodParent = this.nod[0];
		return this;
	},
	value:function(val){
		if(val){
			return this.nod[0].value = val;
		}else{
			return this.nod[0].value;	
		}
	},
	setVal:function(val){
		this.nod[0].innerHTML = val;
	},
	hidden : function(){
		if(arguments.length==0){
			for(var i=0; i<this.nod.length; i++){
				this.nod[i].style.display = 'none';
			}
		}else{
			this.nod[arguments[0]].style.display = 'none';
		}
	},
	show : function(){
		if(arguments.length==0){
			for(var i=0; i<this.nod.length; i++){
				this.nod[i].style.display = 'block';
			}
		}else{
			this.nod[arguments[0]].style.display = 'block';
		}
	},
	setCss:function(pro,val){
		if(KB.bom.webkit){
			return	this.nod[0].style.cssText += pro+":"+val;	
		}
		pro = pro.replace('-','');
		for(var k in this.nod[0].style){			
			if(pro.toLowerCase()==k.toLowerCase()){
				this.nod[0].style[k] = val;
				return;
			}
		}
	},
	css:function(str,target){
		var t = this.nod[0];
		if(target){this.nod[0] = target;}
		str = str.split(/=|,/);
		for(var i=0; i<str.length; i=i+2){
			this.setCss(str[i],str[i+1]);
		}
		this.nod[0] = t;
	},
	set:function(k,v){
		this.nod[0][k] = v;
		return this;
	},
	get:function(k){
		return typeof(this.nod[0][k])=='undefined'?null:this.nod[0][k];
	}
}
KB.sys = function(){
	var bom = {};
    var na = navigator.userAgent.toLowerCase();
    var t;
	(t = na.match(/webkit\/([\d.]+)/)) ? bom.webkit = t[1]:0;
    (t = na.match(/msie ([\d.]+)/)) ? bom.ie = t[1] :
    (t = na.match(/firefox\/([\d.]+)/)) ? bom.firefox = t[1] :
    (t = na.match(/chrome\/([\d.]+)/)) ? bom.chrome = t[1] :
    (t = na.match(/opera.([\d.]+)/)) ? bom.opera = t[1] :
    (t = na.match(/version\/([\d.]+).*safari/)) ? bom.safari = t[1] : 0;
	return bom;
};
KB.bom = KB.sys();
KB.reg = function(target, type, func){
		if (target.addEventListener){
        	target.addEventListener(type, func, false);
		}else if (target.attachEvent){
	        target.attachEvent("on" + type, func);
	    }else{ target["on" + type] = func;}
	}


KB.ready = function(func){ 
   if(!window.__load_events){
	   var init = function (){
          if (arguments.callee.done) return; 
          arguments.callee.done = true; 
          if (window.__load_timer) { 
              clearInterval(window.__load_timer); 
              window.__load_timer = null; 
          } 
          for (var i=0;i < window.__load_events.length;i++) { 
              window.__load_events[i](); 
          } 
          window.__load_events = null; 
      };
	  
      if (document.addEventListener) { 
          document.addEventListener("DOMContentLoaded", init, false); 
      }
	  if(window.attachEvent){
		document.attachEvent("onreadystatechange", function(){
			if ( document.readyState === "complete" ) {
				document.detachEvent( "onreadystatechange", arguments.callee );
				init();
			}
		});
	  }
      if (/WebKit/i.test(navigator.userAgent)) { 
          window.__load_timer = setInterval(function() { 
              if (/loaded|complete/.test(document.readyState)) { 
                  init();
              } 
          }, 10);
      } 
      window.onload = init; 
      window.__load_events = []; 
   }
   window.__load_events.push(func); 
};
KB.getPos = function(elementobj){
	var ms = KB.sys();
	var el = elementobj;
	if(el.parentNode === null || el.style.display == 'none'){ return false;}
	var parent = null;
	var pos = [];
	var box;
	if(el.getBoundingClientRect){
		box = el.getBoundingClientRect();
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		return {x:box.left + scrollLeft, y:box.top + scrollTop};
	}else if(document.getBoxObjectFor){box = document.getBoxObjectFor(el);
		var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
		var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
		pos = [box.x - borderLeft, box.y - borderTop];
	}else{
		pos = [el.offsetLeft, el.offsetTop]; 
		parent = el.offsetParent;    
		if (parent != el) {         
			while (parent) {  
				pos[0] += parent.offsetLeft; 
				pos[1] += parent.offsetTop;  
				parent = parent.offsetParent; 
			}         
		}        
		if (ms.opera||(ms.safari && el.style.position == 'absolute' )) {
			pos[0] -= document.body.offsetLeft;
			pos[1] -= document.body.offsetTop;
		}     
	}
	if (el.parentNode) { parent = el.parentNode; }
	else { parent = null; }
	while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML'){
		pos[0] -= parent.scrollLeft;        
		pos[1] -= parent.scrollTop;
		if (parent.parentNode) { parent = parent.parentNode; }
		else { parent = null; }
	}
	return {x:pos[0], y:pos[1]};
}
KB.format = function(s,t){
	var f = new KB();
	try{
		if(t){
			var a = new Array();
			a.push(s[0]);
			a = a.concat(s);
			f.nod = a;
			return f;
		}
		f.nod[0]=f.nod[1] = s;
	}catch(e){}
	return f;
}
KB.regHover = function(k,class1,class2,unclass,fun){
	/*(k,class1,class2,unclass,fun)=>(KB object,hover className, nuhover className, click_active className, API function)*/
	for(var i=1; i<k.nod.length; i++){
		if(unclass.length>0){if(" "+k.nod[i].className+" ".indexOf(' '+unclass+' ')!=-1){continue;}}
		(function(i){
				KB.reg(k.nod[i],'mouseover',function(){
													 k.css('position=relative',k.nod[i]);
													 if(class1!=null){
													 	k.nod[i].className = class1;
													 }
													 if(fun){fun(k,i,true);} 
													 });
				KB.reg(k.nod[i],'mouseout',function(){
													k.css('position=static',k.nod[i]);
													if(class2!=null){
														k.nod[i].className = class2;
													}
													if(fun){fun(k,i,false);} 
													});
		})(i);
	}
}

var ShortCut = {
	shut:false,
	init:function(){
		KB.reg(ShortCut.cutBtn.nod[0],'mouseover',ShortCut.show);
		KB.reg(ShortCut.cut.nod[0],'mouseout',ShortCut.hidden);
		new KB('b=short_cu').nod[0].title = ShortCut.title1;
	 	ShortCut.hidden();
	},
	open:function(){
		if(!ShortCut.shut){
			ShortCut.cut.show();
			ShortCut.cutBtn.hidden();	
			ShortCut.shut = false;
		}
	},
	show:function(){
		ShortCut.shut = false;
		ShortCut.open();
	},
	hidden:function(){
		if(!ShortCut.shut){
			ShortCut.shut = true;
			ShortCut.close();
		}	
	},
	close:function(){
		if(ShortCut.autoCu){ShortCut.shut = false;return;}
		if(ShortCut.shut){
			ShortCut.cut.hidden();
			ShortCut.cutBtn.show();	
		}
	},
	autoCu:false,
	cu:function(){
		if(ShortCut.autoCu){
			ShortCut.autoCu = false;
			ShortCut.cuBtn.className="icon57";
			ShortCut.cuBtn.title = ShortCut.title1;
		}else{
			ShortCut.autoCu = true;
			ShortCut.cuBtn.className="icon58";
			ShortCut.cuBtn.title = ShortCut.title2;
		}
	}
}
function DHchange(k,i,t){
	var s = k.getNod(i).getChild('div');
	if(s.length>0){
		if(t){
			KB.format(s[0]).show();
		}else{
			KB.format(s[0]).hidden();
		}
	}
}